# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Nicolas Frattaroli <ovdev@fratti.ch>

_realname=pngnq

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1
pkgrel=1
pkgdesc="Pngnq is a tool for quantizing PNG images in RGBA format"
url="http://pngnq.sourceforge.net/"
license=("BSD")
arch=("any")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libpng" "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=("http://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        no-syslog.patch
        configure-mistake.patch)
md5sums=('fdbb94d504931b50c54202b62f98aa44'
         'a42c37e648385985cc2d17ae10b8b22a'
         '39851533d52cf6cafa6d7d748323b3ee')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p0 -i "${srcdir}/no-syslog.patch"
  patch -p1 -i "${srcdir}/configure-mistake.patch"
  
  autoreconf -fi
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  
  sed "35i#include <zlib.h>" -i src/rwpng.c
  
  # The LIBS line fixes some build script weirdness where it only passes the zlib
  # link command to gcc in the right order, but not the libpng one.
  LIBS="`libpng-config --ldflags` -lz" ./configure \
    --prefix=${MINGW_PREFIX} \
    --mandir="${pkgdir}${MINGW_PREFIX}/share/man" 
  make

}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make prefix="${pkgdir}${MINGW_PREFIX}" mandir="${pkgdir}${MINGW_PREFIX}/share/man" install
}
